const Router = require('koa-router');

const query = require('../lib/mysql');
const wrapper = require('../util/wrapper');
const checkError = require('../util/checkError');

const router = new Router();

router.prefix('/api/auth');

module.exports = router;

router.post('/check', async (ctx, next) => {
  const { username,password } = ctx.request.body;
  if (!username || !password) {
    ctx.body = await wrapper(new Error('请求有误.'));
    return false;
  }
  // let list = await query(`select * from lesson where openId="${openId}"`);
  //
  // if (checkError(list) || !Array.isArray(list)) {
  //   ctx.body = await wrapper(new Error('服务异常.'));
  //   return false;
  // }

  ctx.body = wrapper(123);
});

router.post('/login',async(ctx,next)=>{
  const { username,password } = ctx.request.body;
  if (!username || !password) {
    ctx.body = await wrapper(new Error('请求有误.'));
    return false;
  }
  // let list = await query(`select * from lesson where openId="${openId}"`);
  //
  // if (checkError(list) || !Array.isArray(list)) {
  //   ctx.body = await wrapper(new Error('服务异常.'));
  //   return false;
  // }

  ctx.body = wrapper(123);
});

router.post('/logout',async(ctx,next)=>{
  console.log(ctx,next);
});
